package com.amado.springboot.springbootcms.controll;


import com.amado.springboot.springbootcms.domain.Depa;
import com.amado.springboot.springbootcms.domain.Goods;
import com.amado.springboot.springbootcms.domain.User;
import com.amado.springboot.springbootcms.service.DepaService;
import com.amado.springboot.springbootcms.service.GoodsService;
import com.amado.springboot.springbootcms.service.UserService;
import com.amado.springboot.springbootcms.vo.UserLoginVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018\2\26 0026.
 */
@Controller

@RequestMapping("/goods")
@EnableCaching

public class GoodsController {
    private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);
    @Autowired
    private UserService userService;
    @Autowired
    private DepaService depaService;
    @Autowired
    private GoodsService goodsService;
    @GetMapping
    public String index() {

        return "/goods/goodsList";
    }
    @GetMapping("/goodsList")
    @ResponseBody
    public List<Goods> list(Map<String, Object> model) {
        LOGGER.debug("返回值"+goodsService.getAllGoods() );
        return goodsService.getAllGoods();
    }
    @PostMapping("/addGoods")
    @ResponseBody
    public Goods add(Goods goods) {
        LOGGER.debug("进来" + goods);
        goodsService.addGoods(goods);

        LOGGER.debug("返回来" + goodsService.getAllGoods());
        return goods;
    }

    @GetMapping("/toModifyGoods")
    public String get(@RequestParam("id") Long id, HttpServletRequest request) {
        request.setAttribute("user", userService.get(id));
        return "user/userModify";
    }

    @GetMapping("/getGoods")
    public String getUser(@RequestParam("id") Long id, HttpServletRequest request) {

        request.setAttribute("user", userService.get(id));
        return "user/getUser";
    }

    @PostMapping("/modifyGoods")
    @ResponseBody
    public void modify(User user) {
        LOGGER.debug("6地址{}" + user);
        userService.modify(user);

    }

}
